<template>
  <div>
    <van-toast id="van-toast" />

    <div class="container">
      <div class="balance">
        <span class="all">
          <span class="money">{{myMoney}}￥</span>
          <span class="txt">جەمئىي تاپقىنىم</span>
        </span>
        <span class="reamain">
          <span class="money">{{balance}}￥</span>
          <span class="txt">قالدۇق سومما</span>
        </span>
      </div>
      <div
        class="btn"
        @click="WithdrawMoney"
      >
        <button>نەقلەشتۈرۈش</button>
      </div>
    </div>
    <div class="kong"></div>
    <div class="content">
      <div class="top">
        <span class="txt">مېنىڭ تاپقىنىم</span>
      </div>
      <ul>
        <li
          v-for="(item,index) in packetList"
          :key="index"
        >
          <span class="money">￥{{item.award}}</span>
          <span class="time">{{item.create_time}}</span>
          <span class="user-info">
            <span class="name">{{item.userInfo.nickName}}</span>
            <image :src="item.userInfo.avatarUrl"></image>
          </span>
        </li>
      </ul>
    </div>
    <div class="share">
      <button
        class="btn"
        open-type="share"
        :data-rid="wo"
      >ھەمبەھىرلىنەي</button>
    </div>
  </div>
</template>
<script>
import { showTimerToast } from "@/util";

export default {
  data() {
    return {
      userId: "",
      wo: "123",
      packetList: {},
      myMoney: "",
      youCanGet: 0,
      pageIndex: 0,
      balance: 0
    };
  },
  onReachBottom() {
    console.log("ok");
  },
  mounted() {
    let { id } = this.$root.$mp.query;
    this.userId = id;
    let { openId } = wx.getStorageSync("userInfo");
  },
  onShareAppMessage: function(res) {
    let { openId } = wx.getStorageSync("userInfo");
    var that = this;
    return {
      title:
        "قولاي كۆپ ئىقتىدارلىق ئۇنىۋېرسال تەرجىماندىن قىزىل بولاق ئېلىۋېلىڭ",
      // 分享时在路径后拼接参数，可拼接多个参数。
      path: "/pages/Index/main?openId=" + openId,
      imageUrl: "https://wx.2xur7.cn/static/images/event/share1.png", //自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
      success: function(res) {
        // 转发成功
        wx.showToast({
          title: "转发成功",
          icon: "success",
          duration: 2000
        });
      },
      fail: function(res) {
        // 转发失败
        console.log("转发失败");
      }
    };
  },
  onLoad() {
    let { openId } = wx.getStorageSync("userInfo");
    if (!openId) {
      showTimerToast("سىز تېخى كىرمەپسىز", 5000);
      wx.navigateTo({ url: "/pages/Me/main" });
    }
    wx.showLoading();
    this.$http
      .get("https://wx.2xur7.cn/weapp/getRedPacket", {
        openId,
        pageIndex: this.pageIndex
      })
      .then(res => {
        wx.hideLoading();
        // console.log(res.data.data.list);
        this.packetList = res.data.data.list;
        this.everGet = Number(res.data.data.everGet);
        this.myMoney = Number(res.data.data.sum).toFixed(2);
        this.balance = (this.myMoney - this.everGet).toFixed(2);
      });
    wx.hideLoading();
    wx.setNavigationBarColor({
      frontColor: "#ffffff", //前景颜色值，包括按钮、标题、状态栏的颜色，仅支持 #ffffff 和 #000000,
      backgroundColor: "#db4c48"
    });
  },
  methods: {
    WithdrawMoney() {
      if (this.balance >= 10) {
        showTimerToast("ئۈندىدار كۈچۈرۈلدى، قېتىپ قىزىل بولاق ئېلىۋېلىڭ", 3000);
        wx.setClipboardData({
          data: "13122060027", //需要设置的内容,
          success: res => {}
        });
      } else {
        showTimerToast("پۇلىڭىز نەقلەشتۈرۈش ئۆلچىمىگە يەتمىدى", 2000);
      }
    }
  }
};
</script>
<style lang="scss">
.container {
  width: 92%;
  margin: 0 auto;
  .balance {
    width: 100%;
    height: 200rpx;
    margin-top: 30rpx;
    margin-bottom: 30rpx;
    display: flex;
    justify-content: space-around;
    .all,
    .reamain {
      width: 42%;
      height: 100%;
      // border: 1px solid red;
      display: flex;
      justify-content: space-around;
      flex-direction: column;
      text-align: center;
      padding: 25rpx 0;
      box-sizing: border-box;
      .money {
        color: #fe6e5a;
        font-size: 60rpx;
        font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif !important;
      }
      .txt {
        color: #ccc;
      }
    }
    /*  .reamain {
      width: 42%;
      height: 100%;
      border: 1px solid blue;
      display: flex;
    } */
  }
  .btn {
    margin-top: 30rpx;
    width: 80%;
    height: 100rpx;
    margin: 0 auto;
    button {
      color: white;
      width: 100%;
      height: 100%;
      background-color: #fe6e5a;
      border-radius: 100rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      outline: none;
      box-shadow: 0 0 20rpx 8rpx rgba(0, 0, 0, 0.1);
    }
    margin-bottom: 90rpx;
  }
}
.kong {
  width: 100%;
  height: 30rpx;
  background-color: #f8f8f8;
}
.content {
  width: 100%;
  .top {
    height: 100rpx;
    border-bottom: 1rpx solid #eee;
    text-align: right;
    color: #fe6e5a;
    .txt {
      float: right;
      widows: 80rpx;
      direction: rtl;
      margin-right: 50rpx;
      padding-top: 17rpx;
      font-size: 30rpx;
      border-bottom: 2rpx solid #fe6e5a;
      padding-bottom: 10rpx;
      ::after {
        content: "";
        display: inline-block;
        clear: both;
      }
    }
  }
  ul {
    max-height: 600rpx;
    overflow: hidden;
    overflow-y: scroll;
    li {
      height: 100rpx;
      border-bottom: 1rpx solid #f5f5f5;
      display: flex;
      align-items: center;
      justify-content: space-around;
      padding: 0 35rpx;
      flex: 10;
      .money {
        color: #fe6e5a;
        font-size: 30rpx;
        flex: 2;
      }
      .time {
        color: #bbbbbb;
        font-size: 20rpx;
        flex: 3;
        text-align: center;
      }
      .user-info {
        color: #424242;
        font-size: 30rpx;
        flex: 5;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        .name {
          margin-left: 30rpx;
          text-align: center;
          width: 60%;
          line-clamp: 1;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          color: #424242;
        }
        image {
          width: 80rpx;
          height: 80rpx;
          border-radius: 50%;
        }
      }
    }
  }
}
.share {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 375rpx;
  background-image: url(https://wx.2xur7.cn/static/images/event/dibu.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  .btn {
    position: absolute;
    bottom: 110rpx;
    height: 75rpx;
    width: 50%;
    background-color: #f6cb47;
    color: #db4c16;
    left: 0;
    right: 0;
    line-height: 75rpx;
    border-radius: 75rpx;
    box-shadow: 0 0 7rpx 5rpx rgba(0, 0, 0, 0.1);
  }
  button:active {
    box-shadow: 0 -3rpx 7rpx 10rpx rgba(0, 0, 0, 0.1);
  }
}
</style>
